<template>
  <!-- 登录表单 -->
  <el-form ref="form" size="large" autocomplete="off" :model="LoginData"  style="width: 20% ;margin-left: 600px;height: 700px">
    <el-form-item>
      <h1>登录</h1>
    </el-form-item>
    <el-form-item >
      <el-input v-model="LoginData.username" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item >
      <el-input name="password" :prefix-icon="Lock" type="password" placeholder="请输入密码" v-model="LoginData.password"></el-input>
    </el-form-item>
    <el-form-item class="flex">
    </el-form-item>
    <!-- 登录按钮 -->
    <el-form-item>
      <el-button :disabled="LoginData.username==='' || LoginData.password===''" class="button" type="primary" auto-insert-space  @click="login" style="margin-left: 100px">登录</el-button>
    </el-form-item>
<!--    <el-form-item class="flex">-->
<!--      <el-link type="info" :underline="false" @click="isRegister = true;clearRegisterData()" >-->
<!--        注册 →-->
<!--      </el-link>-->
<!--    </el-form-item>-->
  </el-form>
</template>
<script setup>
import {Lock} from "@element-plus/icons-vue";
import {ref} from "vue";
import {useRouter} from 'vue-router'
const router = useRouter()
//定义数据模型
const LoginData=ref({
  username:'',
  password:''
})
import {BUserLogin} from "@/api/user"
import {useTokenSotre} from "@/stores/token"
const token = useTokenSotre()
const login =async ()=>{
  let result=await BUserLogin(LoginData.value)
  token.setToken(result)
  console.log(result)
  router.push('/backend/index')
}
</script>